package com.ruoyi.system.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Goods;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Period;
import com.ruoyi.system.service.IPeriodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/system/period")
public class PeriodController extends BaseController
{
    @Autowired
    private IPeriodService periodService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:period:list')")
    @GetMapping("/list")
    public TableDataInfo list(Period period)
    {
        startPage();
        List<Period> list = periodService.selectPeriodList(period);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:period:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Period period)
    {
        List<Period> list = periodService.selectPeriodList(period);
        ExcelUtil<Period> util = new ExcelUtil<Period>(Period.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:period:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(periodService.selectPeriodById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:period:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Period period)
    {
        return toAjax(periodService.insertPeriod(period));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:period:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Period period)
    {
        return toAjax(periodService.updatePeriod(period));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:period:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(periodService.deletePeriodByIds(ids));
    }

    /**
     * 查询商品列表
     */
    @PreAuthorize("@ss.hasPermi('system:period:list')")
    @GetMapping("/goodsList")
    public TableDataInfo goodsList(Goods goods)
    {
        startPage();
        List<Goods> list = periodService.selectGoodsList(goods);
        return getDataTable(list);
    }
    @GetMapping("/specList")
    public AjaxResult specList() {
        List<Map<String, Object>> specList = periodService.selectSpecList();
        System.out.println("规格列表数据:" + specList); // 添加日志
        return AjaxResult.success(specList);
    }
}
